package com.ruoyi.zyx.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zyx.domain.ZyxRecord;
import com.ruoyi.zyx.service.IZyxRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备档案信息Controller
 * 
 * @author lhs
 * @date 2021-06-08
 */
@RestController
@RequestMapping("/zyx/record")
public class ZyxRecordController extends BaseController
{
    @Autowired
    private IZyxRecordService zyxRecordService;

    /**
     * 查询设备档案信息列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZyxRecord zyxRecord)
    {
        startPage();
        List<ZyxRecord> list = zyxRecordService.selectZyxRecordList(zyxRecord);
        return getDataTable(list);
    }

    /**
     * 导出设备档案信息列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:record:export')")
    @Log(title = "设备档案信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZyxRecord zyxRecord)
    {
        List<ZyxRecord> list = zyxRecordService.selectZyxRecordList(zyxRecord);
        ExcelUtil<ZyxRecord> util = new ExcelUtil<ZyxRecord>(ZyxRecord.class);
        return util.exportExcel(list, "设备档案信息数据");
    }

    /**
     * 获取设备档案信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zyxRecordService.selectZyxRecordById(id));
    }

    /**
     * 新增设备档案信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:record:add')")
    @Log(title = "设备档案信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZyxRecord zyxRecord)
    {
        return toAjax(zyxRecordService.insertZyxRecord(zyxRecord));
    }

    /**
     * 修改设备档案信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:record:edit')")
    @Log(title = "设备档案信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZyxRecord zyxRecord)
    {
        return toAjax(zyxRecordService.updateZyxRecord(zyxRecord));
    }

    /**
     * 删除设备档案信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:record:remove')")
    @Log(title = "设备档案信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zyxRecordService.deleteZyxRecordByIds(ids));
    }
}
